package com.wrs.androidkeepalive.utils;

import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
import android.util.Log;

public class ScreenUtils {
    public static void isScreenLock(Context context, String tag) {
        // 获取KeyguardManager和PowerManager实例
        KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

// 判断是否处于锁屏状态
        boolean isKeyguardLocked = keyguardManager.isKeyguardLocked();
        boolean isKeyguardSecure = keyguardManager.isKeyguardSecure();

// 判断屏幕是否处于亮屏状态
        boolean isScreenOn = powerManager.isInteractive();

// 输出结果
        if (isKeyguardLocked) {
            if (isKeyguardSecure) {
                if (isScreenOn) {
                    Log.e(tag, "屏幕处于锁屏状态，锁屏方式为安全锁屏，屏幕是亮的");
                } else {
                    Log.e(tag, "屏幕处于锁屏状态，锁屏方式为安全锁屏，屏幕是黑的");
                }
            } else {
                if (isScreenOn) {
                    Log.e(tag, "屏幕处于锁屏状态，锁屏方式为非安全锁屏，屏幕是亮的");
                } else {
                    Log.e(tag, "屏幕处于锁屏状态，锁屏方式为非安全锁屏，屏幕是黑的");
                }
            }
        } else {
            if (isScreenOn) {
                Log.e(tag, "屏幕处于解锁状态，屏幕是亮的");
            } else {
                Log.e(tag, "屏幕处于解锁状态，屏幕是黑的");
            }
        }
    }
}
